<?php



if (!headers_sent())
{
	header("Cache-Control: no-cache, must-revalidate");
	header("Pragma: no-cache");
}

require("dbconn.php");

if (isset($_GET["header"])) $header = $_GET["header"];
if (isset($_GET["hourid"])) $sid = $_GET["hourid"];
if (isset($_GET["subject"])) $subject = $_GET["subject"];
else $subject = "";
if (isset($_GET["docentid"])) $docentid = $_GET["docentid"];
else $docentid = "";
if (isset($_GET["classroom"])) $classroom = $_GET["classroom"];
else $classroom = "";



?>			<table rules="top" cellspacing="0" align="left" valign="top">
<?php
		$QUERY = "
			SELECT plaatsnr, vak, docentid, lokaal
			FROM plaats
			WHERE plaatsnr NOT IN
			(
				SELECT plaatsnr
				FROM studieuurplaats
				WHERE studieuur = $sid
			)
			AND vak LIKE '$subject%'
			AND docentid LIKE '$docentid%'
			AND lokaal LIKE '$classroom%'
			ORDER BY lokaal ASC, vak ASC, docentid ASC
			LIMIT 0, 15
			";
			
			//echo "<a style=\"display: none;\">$QUERY\n</a>\n";
			
		$resultdata = mysql_query($QUERY) or die (mysql_error());
		$rows = mysql_numrows($resultdata);

		if ($rows == 0)
		{
		
		
		
?>				<tr id="<?php print($i . $j); ?>" class="choser_hour">
					<td colspan="4">
						geen resultaten
					</td>
				</tr>
<?php



			if (strlen($subject) == 2 && (strlen($docentid) == 2 || strlen($docentid) == 3) && (strlen($classroom) == 2 || strlen($classroom) == 3))
			{
			
				$QUERY = "
					SELECT plaatsnr, vak, docentid, lokaal
					FROM plaats
					WHERE vak LIKE '$subject%'
					AND docentid LIKE '$docentid%'
					AND lokaal LIKE '$classroom%'
					LIMIT 1
					";
				
				//echo "<a style=\"display: none;\">$QUERY\n</a>\n";
					
				$resultdata = mysql_query($QUERY) or die (mysql_error());
				if (mysql_numrows($resultdata) == 0)
				{

?>				<tr id="<?php print($i . $j); ?>" class="choser_hour">
					<td>
						&nbsp;
					</td>
					<td>
						voeg
					</td>
					<td>
						toe!
					</td>
					<td width="20">
						<a class="actionbutton" onclick="addhour('<?php print("$header"); ?>', '<?php print("$sid"); ?>');"><input type="image" src="pics/addweek.png" /></a>
					</td>
				</tr>
<?php		



				}
				else
				{

				
				
?>				<tr id="<?php print($i . $j); ?>" class="choser_hour">
					<td>
						&nbsp;
					</td>
					<td>
						bestaat
					</td>
					<td>
						al!
					</td>
					<td width="20">
						&nbsp;
					</td>
				</tr>
<?php		



				}
			}
		}
		
		for($j=0; $j < $rows; $j++)
		{
			$plaatsnr = mysql_result($resultdata, $j, "plaatsnr");
			$datavak = mysql_result($resultdata, $j, "vak");
			$datadocentid = mysql_result($resultdata, $j, "docentid");
			$datalokaal = mysql_result($resultdata, $j, "lokaal");



?>				<tr id="<?php print($sid . $j); ?>" class="choser_hour">
					<td>
						<?php print($datavak); ?>
					</td>
					<td>
						<?php print($datadocentid); ?>
					</td>
					<td>
						<?php print($datalokaal); ?>
					</td>
					<td>
						<a class="actionbutton" onclick="addplacetoweek('<?php print("$sid"); ?>', '<?php print("$plaatsnr"); ?>')"><img src="pics/addweek.png" /></a>
					</td>
				</tr>
<?php



		}
		
		
		
?>			</table>
